$(function () {
  loadData();
});

/**
 * 标签栏首页点击事件刷新方法
 */
function loadData() {
  getWestIndexModel();
  getEastIndexModel();
}

var westZoneName = '北区';
var eastZoneName = '南区';

/**
 * 获取北区
 */
function getWestIndexModel() {
  $.ajax({
    url: 'index/datamodel/' + westZoneName,
    type: 'GET',
    data: {},
    success: function (res) {
      console.log(res);
      if (res.code === 200) {
        switch (res.data.microWaveStatus) {
          case 0:
            $("span[name='westMwStatusName']").attr("class",
                "label label-primary pull-right");
            break;
          case 1:
            $("span[name='westMwStatusName']").attr("class",
                "label label-success pull-right");
            break;
          case 2:
            $("span[name='westMwStatusName']").attr("class",
                "label label-danger pull-right");
            break;
        }

        if (res.data.heatingUserNickName == null) {
          $("h2[name='westHeatingNickName']").text("无人热饭");
        } else {
          $("h2[name='westHeatingNickName']").text(
              res.data.heatingUserNickName);
        }

        $("span[name='westMwStatusName']").text(res.data.microWaveStatusName);
        $("h1[name='westMwStatusName']").text(res.data.microWaveStatusName);

        $("h1[name='westWaitHeatSum']").text(res.data.waitHeatCount);
        $("h1[name='westHeatSum']").text(res.data.historyHeatCount);

      }
    }
  });
}

/**
 * 获取南区
 */
function getEastIndexModel() {
  $.ajax({
    url: 'index/datamodel/' + eastZoneName,
    type: 'GET',
    data: {},
    success: function (res) {
      if (res.code === 200) {
        switch (res.data.microWaveStatus) {
          case 0:
            $("span[name='eastMwStatusName']").attr("class",
                "label label-primary pull-right");
            break;
          case 1:
            $("span[name='eastMwStatusName']").attr("class",
                "label label-success pull-right");
            break;
          case 2:
            $("span[name='eastMwStatusName']").attr("class",
                "label label-danger pull-right");
            break;
        }

        if (res.data.heatingUserNickName == null) {
          $("h2[name='eastHeatingNickName']").text("无人热饭");
        } else {
          $("h2[name='eastHeatingNickName']").text(
              res.data.heatingUserNickName);
        }

        $("span[name='eastMwStatusName']").text(res.data.microWaveStatusName);
        $("h1[name='eastMwStatusName']").text(res.data.microWaveStatusName);

        $("h1[name='eastWaitHeatSum']").text(res.data.waitHeatCount);
        $("h1[name='eastHeatSum']").text(res.data.historyHeatCount);
      }
    }
  });
}

